<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'header.php'?>
	<div class="page-header">
		<h1>
			<a class="a-back" href="<?= admin_url('classes/classes/' . $gradeInfo['id']) ?>">
				<i class="fa fa-reply"></i>
			</a>
			<?=$classInfo ? '编辑班级信息' : '新增班级'?>
		</h1>
	</div>

	<div class="col-xs-12">
		<form class="form-horizontal" id="classes-form">
			<input type="hidden" name="id" value="<?=$classInfo['id']?>" />
			<input type="hidden" name="grade_id" value="<?=$gradeInfo['id']?>" />
			<!-- <input type="hidden" name="class_master" value="<?=$classInfo['class_master']?>" /> -->
			<input type="hidden" name="class_logo" value="<?=$classInfo['class_logo']?>" />
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">所属校区：</label>
				<div class="col-sm-6">
					<input class="form-control" type="text" disabled="" value="<?=$campusInfo['campus_name']?>" />
				</div>
			</div><div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">所属年级：</label>
				<div class="col-sm-6">
					<input class="form-control" type="text" value="<?=$gradeInfo['grade_name']?>" disabled/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">班级名称：</label>
				<div class="col-sm-6">
					<input class="form-control" type="text" name="class_name" placeholder="请填写班级名称" value="<?=$classInfo['class_name']?>" 
						<?php if($classInfo && $classInfo['x_class_id']): ?>
							readonly
						<?php endif ?>
					/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">班徽上传：</label>
				<div class="col-sm-6">
					<a href="javascript:;" id="upload-img">
						<?php if($classInfo['class_logo']): ?>
							<img class="fit-cover" src="<?=$classInfo['class_logo']?>" width="160" height="160" />
						<?php else: ?>
							<img class="fit-cover" src="<?=$staticAdminUrl?>assets/images/upload.png" width="160" height="160" />
						<?php endif;?>
					</a>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">班级课室：</label>
				<div class="col-sm-6">
					<select class="chosen-select form-control tag-input-style" data-placeholder="选择班级所在课室" name="classroom_id"
						<?php if($classInfo && $classInfo['x_class_id']): ?>
							disabled 
						<?php endif ?>
					>
						<?php foreach($classRoom as $room): ?>
							<option value="<?=$room['id']?>">
								<?=$room['classroom_name']?> <?php if($room['class_name']): ?>【<?=$room['class_name']?>】<?php endif; ?>	
							</option>
						<?php endforeach; ?>
					</select>
					<?php if($classInfo && $classInfo['x_class_id']): ?>
						<input type="hidden" name="classroom_id">
					<?php endif ?>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">班级类型：</label>
				<div class="col-sm-6">
					<select class="form-control" name="class_type"
						<?php if($classInfo && $classInfo['x_class_id']): ?>
							disabled 
						<?php endif ?>
					>
						<option value="<?=CLASSES_TYPE_NORMAL?>"><?=get_class_type_name(CLASSES_TYPE_NORMAL)?></option>
						<option value="<?=CLASSES_TYPE_TEACHING?>"><?=get_class_type_name(CLASSES_TYPE_TEACHING)?></option>
						<!-- <option value="<?=CLASSES_TYPE_ELECTIVE?>"><?=get_class_type_name(CLASSES_TYPE_ELECTIVE)?></option> -->
					</select>
					<?php if($classInfo && $classInfo['x_class_id']): ?>
						<input type="hidden" name="class_type">
					<?php endif ?>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">班级之星：</label>
				<div class="col-sm-6">
					<span class="block input-icon input-icon-right pd0">
					<select class="chosen-select form-control tag-input-style" data-placeholder="请选择班级之星" name="class_star">
						<option value="0"></option>
						<?php foreach($students as $student): ?>
							<option value="<?=$student['id']?>">
								<?=$student['realname']?>	
							</option>
						<?php endforeach; ?>
					</select>
					</span>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">年级之星：</label>
				<div class="col-sm-6">
					<span class="block input-icon input-icon-right pd0">
					<select class="chosen-select form-control tag-input-style" data-placeholder="请选择年级之星" name="grade_star" multiple="multiple">
						<option value="0"></option>
						<?php foreach($teachers as $teacher): ?>
							<option value="<?=$teacher['id']?>">
								<?=$teacher['realname']?>	
							</option>
						<?php endforeach; ?>
					</select>
					</span>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">排序（数值越大越靠前）：</label>
				<div class="col-sm-6">
					<input class="form-control" type="number" name="sort_level" value="<?=$classInfo['sort_level'] ? $classInfo['sort_level'] : 0 ?>" />
				</div>
			</div>
			<!-- <div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">班主任：</label>
				<div class="col-sm-6">
					<span class="block input-icon input-icon-right pd0">
						<input class="width-100" type="text" placeholder="请选择班主任" id="select-master" value="" />
						<i class="ace-icon fa fa-user"></i>
					</span>
				</div>
			</div> -->
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">班级格言：</label>
				<div class="col-sm-6">
					<input class="form-control" type="text" name="class_slogan" placeholder="请填写班级格言" value="<?=$classInfo['class_slogan']?>" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">班级口号：</label>
				<div class="col-sm-6">
					<input class="form-control" type="text" name="class_word" placeholder="请填写班级口号" value="<?=$classInfo['class_word']?>" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">班级简介：</label>
				<div class="col-sm-6">
					<textarea class="pd0" id="content" name="class_content" style="height: 400px;width: 100%"><?=urldecode($classInfo['class_content'])?></textarea>
				</div>
			</div>
			<div class="clearfix">
				<div class="col-md-offset-3 col-md-9">
					<button class="btn btn-info" type="submit">
						<i class="ace-icon fa fa-check"></i> 提交
					</button>
				</div>
			</div>
		</form>
	</div>
<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'footer.php'?>
<!-- 百度编辑器 -->
<script src="<?=$staticAdminUrl?>assets/ueditor/ueditor.config.js"></script>
<script src="<?=$staticAdminUrl?>assets/ueditor/ueditor.all.js"></script>
<script type="text/javascript">
	$(function(){

		<?php if($classInfo): ?>
			$("[name=class_type]").val(<?=$classInfo['class_type']?>);
			$("[name=classroom_id]").val(<?=$classInfo['classroom_id']?>);
			$("[name=class_star]").val(<?=$classInfo['class_star']?>);

			$("[name=grade_star]").val(<?=$classInfo['grade_star']?>);
			<?php if($classInfo['grade_star']): ?>
				var teachIdArray = "<?=$classInfo['grade_star']?>".split(",");
				for(var i in teachIdArray) {
					$("[name=grade_star] [value="+ teachIdArray[i] +"]").attr("selected", "selected");
				}
			<?php endif; ?>
		<?php endif; ?>

		// // 初始化选择老师控件
		// $("#select-master").selectTeacher({
		// 	"callback": function(result) {
		// 		for(var i in result) {
		// 			$("[name=class_master]").val(i);
		// 			$("#select-master").val(result[i].name);
		// 		}
		// 	}
		// });

		// 下拉选择
		$('.chosen-select').chosen({
			search_contains: true
		});

		// 初始化编辑器
		var ue = UE.getEditor('content');

		// 提交表单
		var form = $("#classes-form");
		var submitUrl = "<?=admin_url('classes/save_class_action')?>";
		form_submit(form, submitUrl, function(res) {
			tips_alert(res.msg, res.success, function(){
				if(res.success) {
					window.location.href = "<?=admin_url('classes/classes')?>/<?=$gradeInfo['id']?>";
				}
			});
		});
		var uploadTarget = $("#upload-img");
		// 初始化头像上传插件
		setTimeout(function(){
			uploadTarget.uploader({
				"server":  '<?=UP_FORM_URL?>',
				"authorization": "<?=$signature?>",
				"policy": "<?=$policy?>",
				"callback": function(response) {
					var imgFile = "<?=UP_URL?>" + response.url;
					uploadTarget.find("img").attr("src", imgFile);
					form.find("[name=class_logo]").val(imgFile);
				}
			});
		}, 200)
	})
</script>